package com.hontech.pastacooking.model

import com.hontech.pastacooking.serial.UInt16
import com.hontech.pastacooking.serial.UInt8


class HeaterStatus {

    val appVersion = UInt16()
    val nozzle = UInt8()
    val waterTemp = UInt16()
    val steamTemp = UInt16()
    val steamKpa = UInt16()
    val sensor = UInt16()
    val flag = UInt16()
    val count = UInt16()
    val drawType = UInt8()
    val heatType = UInt8()

    fun isHeatMode() = (heatType.value == 0x01)

    fun isWaterTempOk() = (waterTemp.value >= 93)
    fun isSteamKpaOk() = (steamKpa.value >= 350)

    fun isNozzleOrigin() = sensor.isSetBit(0)
    fun isNozzleFault() = sensor.isSetBit(1)
    fun isWaterTempFault() = sensor.isSetBit(2)
    fun isSteamTempFault() = sensor.isSetBit(3)
    fun isLeak() = sensor.isSetBit(4)
    fun isWaterLow() = sensor.isSetBit(5)
    fun isWaterHigh() = sensor.isSetBit(6)
    fun isSteamLow() = sensor.isSetBit(7)
    fun isSteamHigh() = sensor.isSetBit(8)
    fun isNozzleBottomOrigin() = sensor.isSetBit(9)
    fun isInsideBucketOk() = !sensor.isSetBit(10)
    fun isExternBucketOk() = !sensor.isSetBit(11)

    fun isValve1Open() = flag.isSetBit(0)
    fun isValve2Open() = flag.isSetBit(1)
    fun isValve3Open() = flag.isSetBit(2)
    fun isValve4Open() = flag.isSetBit(3)
    fun isValve5Open() = flag.isSetBit(4)
    fun isValve6Open() = flag.isSetBit(5)
    fun isValve7Open() = flag.isSetBit(6)
    fun isValve8Open() = flag.isSetBit(7)
    fun isValve9Open() = flag.isSetBit(8)
    fun isWaterHeatOpen() = flag.isSetBit(9)
    fun isSteamHeatOpen() = flag.isSetBit(10)
    fun isWaterPumpOpen() = flag.isSetBit(11)
    fun isSteamPumpOpen() = flag.isSetBit(12)
    fun isNozzlePumpOpen() = flag.isSetBit(13)
    fun isFanOpen() = flag.isSetBit(14)

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as HeaterStatus

        if (appVersion != other.appVersion) return false
        if (nozzle != other.nozzle) return false
        if (waterTemp != other.waterTemp) return false
        if (steamTemp != other.steamTemp) return false
        if (steamKpa != other.steamKpa) return false
        if (sensor != other.sensor) return false
        if (flag != other.flag) return false
        if (count != other.count) return false
        if (drawType != other.drawType) return false
        if (heatType != other.heatType) return false

        return true
    }

    override fun hashCode(): Int {
        var result = appVersion.hashCode()
        result = 31 * result + nozzle.hashCode()
        result = 31 * result + waterTemp.hashCode()
        result = 31 * result + steamTemp.hashCode()
        result = 31 * result + steamKpa.hashCode()
        result = 31 * result + sensor.hashCode()
        result = 31 * result + flag.hashCode()
        result = 31 * result + count.hashCode()
        result = 31 * result + drawType.hashCode()
        result = 31 * result + heatType.hashCode()
        return result
    }

}



